<?php

namespace Auth\Form;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Input;
use Zend\Form\Element;

class LoginFilter extends InputFilter {

    public function __construct($sm) {

	// self::__construct(); // parnt::__construct(); - trows and error
	$this->add(array(
	    'name' => 'username', // 'usr_name'
	    'required' => true,
	    'filters' => array(
		array('name' => 'StripTags'),
		array('name' => 'StringTrim'),
	    ),
	    'validators' => array(
		array(
		    'name' => 'NotEmpty',
		    'break_chain_on_failure' => true,
		    'options' => array(
			'messages' => array(
			    \Zend\Validator\NotEmpty::IS_EMPTY => 'Please enter your user name!'
			),
		    )
		),
		array(
		    'name' => 'StringLength',
		    'break_chain_on_failure' => true,
		    'options' => array(
			'encoding' => 'UTF-8',
			'min' => 5,
			'max' => 255,
		    ),
		),
		array(
		    'name' => 'DoctrineModule\Validator\ObjectExists',
		    'break_chain_on_failure' => true,
		    'options' => array(
			'object_repository' => $sm->get('doctrine.entitymanager.orm_default')->getRepository('Auth\Entity\Users'),
			'fields' => 'usrName',
			'messages' => array(
			    'noObjectFound' => 'The user name you entered is incorrect.'
			)
		    ),
		),
	    ),
	));

	$this->add(array(
	    'name' => 'password', // usr_password
	    'required' => true,
	    'filters' => array(
		array('name' => 'StripTags'),
		array('name' => 'StringTrim'),
	    ),
	    'validators' => array(
		array(
		    'name' => 'NotEmpty',
		    'break_chain_on_failure' => true,
		    'options' => array(
			'messages' => array(
			    \Zend\Validator\NotEmpty::IS_EMPTY => 'Please enter your password!'
			),
		    )
		),
		array(
		    'name' => 'StringLength',
		    'break_chain_on_failure' => true,
		    'options' => array(
			'encoding' => 'UTF-8',
			'min' => 6,
			'max' => 255,
		    ),
		),
	    ),
	));
    }

}
